/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.minhphuong.bll;

import com.minhphuong.dal.HelperDAL;
import com.minhphuong.entities.*;
import com.minhphuong.helper.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.ui.ModelMap;

/**
 *
 * @author QuocMinh
 */
public class HelperBLL {

    public static void LoadGiaoDien(ModelMap map, HttpSession session) {
        NguoiDung checkSession = NguoiDungBLL.checkSession(session);
        map.addAttribute("checkSession", checkSession);

        List<Hang> listHang = HangBLL.getAllHang();
        map.addAttribute("listHang", listHang);

        List<BaiViet> listBaiViet = BaiVietBLL.getAllBaiViet();
        map.addAttribute("listBaiViet", listBaiViet);

        KhuyenMai khuyenMai = KhuyenMaiBLL.getKhuyenMai();
        map.addAttribute("khuyenMai", khuyenMai);

        String ngayHienTai = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        map.addAttribute("ngayHienTai", ngayHienTai);

        int count_session = 0;
        List<SanPham> listSanPhamCountSession = SanPhamBLL.getAllSanPham();
        for (SanPham sanPham : listSanPhamCountSession) {
            if (session.getAttribute("" + sanPham.getMaSp()) != null) {
                count_session++;
            }
        }
        map.addAttribute("count_session", count_session);

    }

    public static int getNextID(String table, String column) {
        return HelperDAL.getNextID(table, column);
    }
}
